package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTypeEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LimitChooseRangePoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SerialNumberPoJo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.InventoryEnum;
import com.xbongbong.saas.enums.dictionary.InventoryNewStatusEnum;
import com.xbongbong.saas.enums.dictionary.InventoryStatusEnum;
import com.xbongbong.saas.enums.dictionary.InventoryTypeEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import lombok.Getter;
import java.util.Objects;

/**
 * TempInventoryEnum
 *
 * @author GuoJun.HU
 * @since V1.0
 * @date 2019/2/19 11:07
 */
@Getter
public enum TempInventoryEnum {
    //
    BASE_INFO(InventoryEnum.BASE_INFO),
    SHEET_NO(InventoryEnum.SHEET_NO),
    INVENTORY_STATUS(InventoryEnum.INVENTORY_STATUS),
    INVENTORY_TYPE(InventoryEnum.INVENTORY_TYPE),
    WAREHOUSE_ID(InventoryEnum.WAREHOUSE_ID),
    MANAGER_ID(InventoryEnum.MANAGER_ID),
    TIME(InventoryEnum.TIME),
    PRODUCT(InventoryEnum.PRODUCT),
    MEMO(InventoryEnum.MEMO),

    SYSTEM_INFO(InventoryEnum.SYSTEM_INFO),
    CREATOR_ID(InventoryEnum.CREATOR_ID),
    ADD_TIME(InventoryEnum.ADD_TIME),
    UPDATE_TIME(InventoryEnum.UPDATE_TIME),

    INSTOCK_ID(InventoryEnum.INSTOCK_ID),
    OUTSTOCK_ID(InventoryEnum.OUTSTOCK_ID),
    IF_PROFIT(InventoryEnum.IF_PROFIT),
    IF_LOSS(InventoryEnum.IF_LOSS),
    PRODUCT_CATEGORY(InventoryEnum.PRODUCT_CATEGORY),
    WAREHOUSE_ID_LINKED_TEXT(InventoryEnum.WAREHOUSE_ID_LINKED_TEXT),
    STATUS(InventoryEnum.STATUS),


    ;
    private InventoryEnum anEnum;

    TempInventoryEnum(InventoryEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempInventoryEnum> getAllEnum() {
        List<TempInventoryEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    // ===================================模板字段初始化======================================

    /**
     * 初始化编号
     * @param fieldAttrEntity 字段属性实体
     */
    public static void initSheetNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.INVENTORY.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.INVENTORY.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SHEET_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        // 不能重复
        fieldAttrEntity.setNoRepeat(1);
        // 默认的编号规则
        SerialNumberPoJo serialNumberPoJo = InitExplainsHelper.setSerialNumber(SerialNumberEnum.INVENTORY_NO);
        fieldAttrEntity.setSerialNumber(serialNumberPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }


    /**
     * 初始化负责人
     *
     * @param fieldAttrEntity 字段属性实体
     * @author chaoxiong.lei
     * @date 11:01 2019/1/18
     **/
    public static void initManagerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(0);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        // 默认的查询范围
        LimitChooseRangePoJo limitChooseRangePoJo = new LimitChooseRangePoJo();
        fieldAttrEntity.setLimitChooseRange(limitChooseRangePoJo);
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setLinkedText(WAREHOUSE_ID_LINKED_TEXT.anEnum.getAttr());
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.WAREHOUSE_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.WAREHOUSE_MANAGER));
    }

    /**
     * 初始化仓库
     *
     * @param fieldAttrEntity 字段属性实体
     * @author feng.zheng
     * @date 2019/2/15 19:38
     */
    public static void initWarehouseId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
        fieldAttrEntity.setLinkedText(WAREHOUSE_ID_LINKED_TEXT.anEnum.getAttr());
//        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
//        saasParticularAttributePoJo.setRelyType("base");
//        saasParticularAttributePoJo.setRelyMode(XbbRefTypeEnum.WAREHOUSE.getAlias());
//        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }
    /**
     * 初始化产品
     *
     * @param fieldAttrEntity 属性
     * @author feng.zheng
     * @date 2019/2/26 20:25
     */
    public static void initProducts(FieldAttrEntity fieldAttrEntity) {
//        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
//        saasParticularAttributePoJo.setRelyBusiness(XbbRefTypeEnum.WAREHOUSE.getCode());
//        saasParticularAttributePoJo.setRelyType("relied");
//        saasParticularAttributePoJo.setRelyMode(XbbRefTypeEnum.WAREHOUSE.getAlias());
//        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        //由后端逻辑控制
//        fieldAttrEntity.setNoEditable(1);
    }

    /**
     * 初始化状态
     *
     * @param fieldAttrEntity 实体
     */
    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
//        List<ItemPoJo> itemPoJos = new ArrayList<>();
//        ItemPoJo itemPoJo1 = new ItemPoJo();
//        itemPoJo1.setText(InventoryStatusEnum.WAIT_OUT_INSTOCK.getName());
//        itemPoJo1.setValue(InventoryStatusEnum.WAIT_OUT_INSTOCK.getCode());
//        itemPoJos.add(itemPoJo1);
//        ItemPoJo itemPoJo2 = new ItemPoJo();
//        itemPoJo2.setText(InventoryStatusEnum.ALREADY_OUT_INSTOCK.getName());
//        itemPoJo2.setValue(InventoryStatusEnum.ALREADY_OUT_INSTOCK.getCode());
//        itemPoJos.add(itemPoJo2);
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(InventoryStatusEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initTime(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setDateType(DateTypeEnum.YMD.getAlias());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initInventoryStatus(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsDictionary(1);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setEditable(0);
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(InventoryNewStatusEnum.class, fieldAttrEntity.getFieldType());
        List<String> shipStatusCodeList = Arrays.asList(InventoryNewStatusEnum.UNFINISHED.getName(), InventoryNewStatusEnum.FINISHED.getName());
        for (ItemPoJo itemPoJo: itemPoJos) {
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (!shipStatusCodeList.contains(itemPoJo.getText())) {
                itemPoJo.setShowType(ShowTypeEnum.NONE.getCode());
                itemPoJo.setEditHide(1);
            } else {
                if (Objects.equals(itemPoJo.getText(), InventoryNewStatusEnum.UNFINISHED.getName())) {
                    itemPoJo.setChecked(true);
                }
            }
        }
        List<String> settingList = Arrays.asList(ForbiddenSettingEnum.DISABLE_OPTION_RELY.getAlias(), ForbiddenSettingEnum.DISABLE_SELF_DEFINE.getAlias());
        fieldAttrEntity.setForbiddenSettingList(settingList);
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setItems(itemPoJos);
    }

    public static void initInventoryType(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsDictionary(1);
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setMemo("快速盘点主要适用于日常即时盘点，保存后即刻调整库存。标准盘点主要适用于按月盘点或按周盘点等定期盘点业务，保存后需手动生成出入库单调整库存");
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setAdvancedSetHide(1);
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(InventoryTypeEnum.class, fieldAttrEntity.getFieldType()));
    }
}
